package com.kajespero.model;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Text;
import com.kajespero.enums.TemplateType;
import com.kajespero.vo.TemplateVO;

@PersistenceCapable(detachable="true")
public class TemplateBean extends IdentifierVOBean<Long> implements TemplateVO{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1295092369573232757L;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	private Long id;
	
	@Persistent
	private String title;
	
	@Persistent(column="value")
	private Text value;
	
	@Persistent
	private String type;
	

	@Override
	public Long getId() {
		return this.id;
	}

	@Override
	public String getTitle() {
		return this.title;
	}

	@Override
	public String getValue() {
		if(this.value != null){
			return this.value.getValue();
		}
		return null;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setValue(String value) {
		this.value = new Text(value);
	}

	@Override
	public TemplateType getType() {
		if(this.type != null && !this.type.isEmpty()){
			return TemplateType.valueOf(this.type);
		}
		return null;
	}
	
	public void setType(TemplateType type){
		this.type = type.name();
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

}
